package com.star.controller.business;

import com.star.result.Result;
import com.star.service.ReportService;
import com.star.vo.OrderReportVO;
import com.star.vo.SalesTop10ReportVO;
import com.star.vo.TurnoverReportVO;
import com.star.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;

@RestController("businessReportController")
@RequestMapping("/business/report")
@Slf4j
@Api(tags = "商家端数据统计相关接口")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 统计指定时间内的营业额数据
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/turnoverStatistics")
    @ApiOperation("营业额统计")
    public Result<TurnoverReportVO> getTurnoverStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                      @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end, Long businessId){
        log.info("统计指定时间内的营业额数据{}{}{}", begin, end, businessId);
        TurnoverReportVO turnoverReportVO =  reportService.getTurnoverStatistics(begin, end, businessId);
        return Result.success(turnoverReportVO);
    }

    /**
     * 统计指定时间内的订单数据
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/ordersStatistics")
    @ApiOperation("统计指定时间内的订单数据")
    public Result<OrderReportVO> getOrderStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                    @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                                                    Long businessId){
        log.info("统计指定时间内的订单数据{}{}{}", begin, end, businessId);
        OrderReportVO orderReportVO = reportService.getOrderStatistics(begin, end, businessId);
        return Result.success(orderReportVO);
    }

    /**
     * 查询销量排名top10
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("/top10")
    @ApiOperation("查询销量排名top10")
    public Result<SalesTop10ReportVO> getSalesTop10(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                                                    @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
                                                    Long businessId){
        log.info("查询销量排名top10{}{}{}", begin, end,businessId);
        SalesTop10ReportVO salesTop10ReportVO = reportService.getSalesTop10(begin, end, businessId);
        return Result.success(salesTop10ReportVO);
    }

    /**
     * 导出Excel报表接口
     * @param response  获取输入流
     */
    @GetMapping("/export")
    @ApiOperation("导出Excel报表接口")
    public Result export(HttpServletResponse response){
        log.info("导出Excel报表接口");
//        reportService.exportBusinessData(response);
        return Result.success();
    }
}
